#ifndef __GLDRAW_H__
#define __GLDRAW_H__
#pragma once
//#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "ResourceManager.h"

class GLDraw
{
public:
	void GLDrawPlane(char *_textureName, 
		float _posX, float _posY, float _posZ,
		float _sizeX, float _sizeY, int _isH,
		float _colorR, float _colorG, float _colorB, float _colorA)
	{
		glPushMatrix();
		glTranslatef(_posX, _posY, _posZ);
		glEnable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glColor4f(_colorR, _colorG, _colorB, _colorA);

		ResourceManager::GetInst()->LoadTexture(_textureName);

		float ww = (float) _sizeX / 2;
		float hh = (float) _sizeY / 2;
		//v=1 nam ngang (y=0), v=0 nam doc (z=0)
		int i,j;
		if(_isH == 1) 
		{
			i = 0;
			j = 1;
		}
		else 
		{
			i = 1;
			j = 0;
		}

		glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(ww,hh*i,-hh*j);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-ww,hh*i,-hh*j);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-ww,-hh*i,hh*j);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(ww,-hh*i,hh*j);
		glEnd();

		glDisable(GL_TEXTURE_2D);
		glPopMatrix();
	}


	void GLDrawScore(int _score, float _posX, float _posY, float _posZ, float _width, float _heigh)
	{
		glPushMatrix();
		glTranslatef(_posX, _posY, _posZ);

		glEnable(GL_BLEND);
		//glBlendFunc(GL_SRC_ALPHA, GL_ONE);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glEnable(GL_TEXTURE_2D);


		ResourceManager::GetInst()->LoadTexture("Resource/Image/SP_Number.png");


		float w,h;
		w = _width/2;
		h = _heigh/2;
		float _left, _right, _bot, _top;
		int unit, dozen;
		unit = _score % 10;
		dozen = _score / 10;

		glBegin(GL_QUADS);

		///ve o ben trai (dozen)

		if(dozen < 5)
		{
			_top = 0.5;
			_bot = 0;
			_left = (float) dozen / 5;
			_right = _left + 0.2;
		}
		else
		{
			_top = 1.0;
			_bot = 0.5;
			_left = (float) (dozen - 5) / 5;
			_right = _left + 0.2;
		}
		glTexCoord2f(_right, _bot); glVertex3f(0, -h, 0);
		glTexCoord2f(_left, _bot); glVertex3f(-w, -h, 0);
		glTexCoord2f(_left, _top); glVertex3f(-w, h, 0);
		glTexCoord2f(_right, _top); glVertex3f(0, h, 0);

		/// ve ben phai
		if(unit < 5)
		{
			_top = 0.5;
			_bot = 0;
			_left = (float) unit / 5;
			_right = _left + 0.2;
		}
		else
		{
			_top = 1.0;
			_bot = 0.5;
			_left = (float) (unit - 5) / 5;
			_right = _left + 0.2;
		}
		glTexCoord2f(_right, _bot); glVertex3f(w, -h, 0);
		glTexCoord2f(_left, _bot); glVertex3f(0, -h, 0);
		glTexCoord2f(_left, _top); glVertex3f(0, h, 0);
		glTexCoord2f(_right, _top); glVertex3f(w, h, 0);
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_BLEND);
		glEnd();

		glPopMatrix();
	}

};
/// _isH: nam ngang 1, nam dung 0

#endif